package com.example.opengldemo.ndk;

import android.app.ActivityManager;
import android.content.Context;
import android.content.res.AssetManager;
import android.opengl.GLSurfaceView;
import android.util.Log;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class MyNDKView extends GLSurfaceView implements GLSurfaceView.Renderer {

    static {
        System.loadLibrary("myLib");
    }
    native public void glesInit() ;
    native public void glesResize(int width, int height ) ;
    native public void glesRenderer () ;
    native public void loadAssetManager (AssetManager manager) ;
    AssetManager manager ;
     public MyNDKView(Context context) {
        super(context);
        manager = context.getAssets();
        if(manager == null){
            Log.e("MyNDKView" , "init Asset Manager fail") ;
        }
        initConfig() ;
    }

    private void initConfig() {
        setEGLContextClientVersion(3);
        setRenderer(this);
        this.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }


    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        loadAssetManager(this.manager);
        glesInit();
    }


    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        glesResize(width  , height) ;
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        glesRenderer();
    }
}
